<?php
class View_Tour {
	
	public static function showTourBlocks(array $arrTours, City $objCity) {
		echo '<div class="tour-blocks">';
			echo '<h3 class="std-h">Горящие туры ' . $objCity->getField('city_name_2') . '</h3>';
			foreach ($arrTours as $arrTour) self::showOneTourBlock($arrTour);
			echo '<div class="clear"></div>';
		echo '</div>';
	}

	public static function showOneTourBlock(array $arrTour) {
		echo '<div class="tour-block">';
			echo '<a class="poster" title="' . $arrTour['hotel_name'] . ', ' . $arrTour['city_name_ru'] . ', ' . $arrTour['country_name_ru'] . '" href="http://level.travel' . $arrTour['img_full_size'] . '"><img src="http://level.travel' . $arrTour['img_preview'] . '"></a>';
			echo '<div class="location">';
				echo '<div class="flag flag-' . $arrTour['iso'] . '"></div>';
				echo '<a href="/tour/' . $arrTour['ID_lvl_tour'] . '" title="' . $arrTour['country_name_ru'] . ', ' . $arrTour['city_name_ru'] . '" rel="nofollow" target="_blank">' . Service_Function::utf8_string_with_limit($arrTour['country_name_ru'] . ', ' . $arrTour['city_name_ru'], 18) . '</a>';
			echo '</div>';
			echo '<div class="hotel">';
				echo '<a href="#" title="' . $arrTour['hotel_name'] . '">' . Service_Function::utf8_string_with_limit($arrTour['hotel_name'], 23) . '</a>';
				echo '<div class="hotel-info">';
					if ($arrTour['stars']) echo '<div class="stars"><div class="star star' .  $arrTour['stars']. '"></div></div>';
					echo '<p>' . $arrTour['description'] . '</p>';
				echo '</div>';
			echo '</div>';
			echo '<div class="price">Цена от ' . $arrTour['min_price'] . ($arrTour['max_price'] != $arrTour['min_price'] ? ' до ' . $arrTour['max_price'] : '') . '</div>';
		echo '</div>';
	}
	
	public static function showCountryPage(Country $objCountry, array $arrPhotoIds, Article $objArticle, array $arrResorts, array $arrWeathers, array $arrWeathersResort) {
		
		echo '<div class="country">';
			View_Photo::showGallery($arrPhotoIds);
			self::showCountryInfoBlock($objCountry);
			echo '<div class="clear"></div>';
			View_Article::showArticleText($objArticle->getField('article_text'));
			if (!empty($arrWeathers)) self::showWeather($objCountry, $arrResorts, $arrWeathers, $arrWeathersResort);
			if (!empty($arrResorts)) self::getResortList($objCountry, $arrResorts);
		echo '</div>';
		
	}
	
	public static function showWeather(Country $objCountry, array $arrResorts, array $arrWeathers, array $arrWeathersResort) {
		echo '<div class="weather">';
			echo '<table class="design-table">';
				echo '<tr>';
					echo '<th></th>';
					for ($i = 1; $i < 13; $i++) echo '<th>' . Service_Date::getMonth($i) . '</th>';
				echo '</tr>';
				echo '<tr>';	
					echo '<td class="resort-name"><b>' . $objCountry->getField('country_name') . '</b></td>';
					foreach ($arrWeathers as $arrWeather) echo '<td>' . $arrWeather['temp'] . '&deg;</td>';
				echo '</tr>';
				foreach ($arrWeathersResort as $resordId => $arrWeathers) {
					echo '<tr>';
						echo '<td class="resort-name">' . $arrResorts[$resordId]['resort_name'] . '</td>';
						foreach ($arrWeathers as $arrWeather) echo '<td>' . $arrWeather['temp'] . '&deg;</td>';
					echo '</tr>';
				}
			echo '</table>';
		echo '</div>';
	}
	
	public static function showWeatherResort(array $arrWeathers) {
		echo '<div class="weather">';
			echo '<table class="design-table">';
				echo '<tr>';
					for ($i = 1; $i < 13; $i++) echo '<th>' . Service_Date::getMonth($i) . '</th>';
				echo '</tr>';
				echo '<tr>';
					foreach ($arrWeathers as $arrWeather) echo '<td>' . $arrWeather['temp'] . '&deg;</td>';
				echo '</tr>';
			echo '</table>';
		echo '</div>';
	}
	
	public static function showCountryInfoBlock(Country $objCountry){
		echo '<div class="info-block">';
		
			echo '<h3 class="std-h">Справочная информация</h3>';
		
			
			echo '<div class="info">';
				echo '<div class="name">Флаг</div>';
				echo '<div class="flag flag-' . $objCountry->getField('iso') . '"></div>';
			echo '</div>';
			
			echo '<div class="info">';
				echo '<div class="name">Столица:</div>';
				echo $objCountry->getField('capital');
			echo '</div>';
			
			echo '<div class="info">';
				echo '<div class="name">Виза:</div>';
				echo $objCountry->getField('visa');
			echo '</div>';
			
			echo '<div class="info">';
				echo '<div class="name">Валюта:</div>';
				echo $objCountry->getField('currency');
			echo '</div>';
			
			echo '<div class="info">';
				echo '<div class="name">Язык:</div>';
				echo $objCountry->getField('lang');
			echo '</div>';
			
			echo '<div class="info">';
				echo '<div class="name">Население:</div>';
				echo 'Более ' . $objCountry->getField('population') . ' млн.';
			echo '</div>';
			
			echo '<div class="info">';
			echo '<div class="info">';
				echo '<div class="name">Лететь из Москвы:</div>';
				echo $objCountry->getField('fly_moscow');
			echo '</div>';
			
				echo '<div class="name">Часовой пояс:</div>';
				echo $objCountry->getField('timezone');
				echo ' (разница с Москвой ' . (floatval($objCountry->getField('timezone')) - 4) . ' ч.)';
			echo '</div>';
			
			echo '<div class="info last">';
				echo '<div class="name">Телефонный код:</div>';
				echo $objCountry->getField('phone_code');
			echo '</div>';
			
			
		echo '</div>';
	}
	
	public static function getResortList(Country $objCountry, array $arrResorts) {
		shuffle($arrResorts);
		$arrResorts = array_slice($arrResorts, 0, 4);
		echo '<div class="resort-list">';
			echo '<h3 class="std-h">Популярные курорты</h3>';
			foreach ($arrResorts as $arrResort) {
				$url = '/' . $objCountry->getField('country_url') . '/' . $arrResort['resort_url'];
				echo '<div class="one-resort">';
					echo '<a href="' . $url . '"><img src="' . View_Photo::getUrl($arrResort['ID_photo'], '215x130') . '"></a>';
					echo '<a href="' . $url . '" class="name">' . $arrResort['resort_name'] . '</a>';
				echo '</div>';
			}
			echo '<div class="clear-left"></div>';
		echo '</div>';
	}
}